﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using SpLocalizer.Common;
using Microsoft.SharePoint;
using Microsoft.Practices.Unity;

namespace SpLocalizer.ContentSourceProviders.SpListItems
{
    internal class SpListItemLookupValueLocalizationTask : SpListItemAbstractValueLocalizationTask
    {
        protected override string GetFieldTextToTranslate(SPListItem item)
        {
            SPFieldLookupValue LookupValue = new SPFieldLookupValue(item[this.FieldId].ToString());
            if (LookupValue != null)
            {
                return LookupValue.LookupValue;
            }
            else
            {
                return null;
            }

                
        }

        internal override void SetFieldTextValue(SPListItem item)
        {
            SPFieldLookupValue LookupValue = new SPFieldLookupValue(item[this.FieldId].ToString());
            SPFieldLookupValue newLookupValue = new SPFieldLookupValue(LookupValue.LookupId, this.TranslatedText);

            item[this.FieldId] = newLookupValue.ToString();
           
        }
    }
}
